//
//  ActivityCell.m
//  MapList
//
//  Created by Wu Chenhao on 6/2/12.
//  Copyright (c) 2012 MicroStrategy. All rights reserved.
//

#import "ActivityCell.h"
#import "UIColor+XMin.h"
@implementation ActivityCell

@synthesize actView;
@synthesize panel1;
@synthesize actNameLabel;
@synthesize editButton;
@synthesize editImage1;
@synthesize editImage2;

@synthesize panel2;
@synthesize locationImageView;
@synthesize locationImage;
@synthesize locationLabel;
@synthesize seperateLineView;
@synthesize seperateLine;
@synthesize distanceImageView;
@synthesize distanceImage;
@synthesize distanceLabel;

@synthesize panel3;
@synthesize wanchengButton;
@synthesize tuichuButton;

@synthesize completeButton;
@synthesize exitButton;

@synthesize bluePanel;
@synthesize wanchengLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    // Initialization code
    CGRect cellFrame = CGRectMake(0, 0, 300, 110);
    actView = [[UIView alloc] initWithFrame:cellFrame];
    actView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    //actView.userInteractionEnabled = YES;
    [self addSubview:actView];
    //[self setSelectionStyle:UITableViewCellSelectionStyleNone];
    self.clipsToBounds = YES;
    
    if ([self.reuseIdentifier isEqualToString:@"OrangeCell"]){
        panel3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, -40, 300, 70)];
        UIImage *panel3Image = [UIImage imageNamed:@"cellPanel3.png"];
        panel3.image = panel3Image;
        panel3.userInteractionEnabled = YES;
        
        panel1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
        UIImage *panel1Image = [UIImage imageNamed:@"cellPanel1.png"];
        panel1.image = panel1Image;
        panel1.userInteractionEnabled = YES;
        
        panel2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 300, 70)];
        UIImage *panel2Image = [UIImage imageNamed:@"cellPanel2.png"];
        panel2.image = panel2Image;
        panel2.userInteractionEnabled = YES;
        
        [actView addSubview:panel2];
        [actView addSubview:panel3];
        [actView addSubview:panel1];
        //[actView addSubview:panel4];
        
        //add controls into panel1
        actNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 260, 30)];
        //actNameLabel.text = @"5月环千岛湖";
        actNameLabel.textAlignment = UITextAlignmentLeft;
        actNameLabel.textColor = [UIColor whiteColor];
        actNameLabel.backgroundColor = [UIColor clearColor];
        actNameLabel.font = [UIFont fontWithName:@"Arial" size:20];
        [panel1 addSubview:actNameLabel];
        
        
        editButton = [[UIImageView alloc] initWithFrame:CGRectMake(270, 5, 20, 20)];
        //editButton = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 110)];
        editImage1 = [UIImage imageNamed:@"actEditUnactive.png"];
        editImage2 = [UIImage imageNamed:@"actEditActive.png"];
        editButton.userInteractionEnabled = YES;
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(editButtonTap:)];
        //[editButton addGestureRecognizer:singleTap]; 
        editButton.image = self.editImage1;
        [panel1 addSubview:editButton];
        panel1.userInteractionEnabled = YES;
        [panel1 addGestureRecognizer:singleTap];
        
        
        locationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 25, 11, 16)];
        locationImage = [UIImage imageNamed:@"地点图标"];
        locationImageView.image = locationImage;
        [panel2 addSubview:locationImageView];
        
        
        locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, 25, 100, 16)];
        //locationLabel.text = @"杭州市 滨江区";
        locationLabel.textAlignment = UITextAlignmentLeft;
        locationLabel.textColor = [UIColor getColor:@"D0D0D0"];
        locationLabel.backgroundColor = [UIColor clearColor];
        locationLabel.font = [UIFont fontWithName:@"Arial" size:15];
        [panel2 addSubview:locationLabel];
        
        seperateLineView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 8, 1, 52)];
        seperateLine = [UIImage imageNamed:@"竖分割线"];
        seperateLineView.image = seperateLine;
        [panel2 addSubview:seperateLineView];
        
        distanceImageView = [[UIImageView alloc] initWithFrame:CGRectMake(175, 25, 15, 15)];
        distanceImage = [UIImage imageNamed:@"距离图标1"];
        distanceImageView.image = distanceImage;
        [panel2 addSubview:distanceImageView];
        
        distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 23, 100, 19)];
        //distanceLabel.text = @"239.7KM";
        distanceLabel.textAlignment = UITextAlignmentLeft;
        distanceLabel.textColor = [UIColor getColor:@"FC570E"];
        distanceLabel.backgroundColor = [UIColor clearColor];
        distanceLabel.font = [UIFont fontWithName:@"Arial" size:20];
        [panel2 addSubview:distanceLabel];
        
//        UIImageView *tapEditButtonView = [[UIImageView alloc] initWithFrame:CGRectMake(250, 0, 60, 50)];
//        tapEditButtonView.userInteractionEnabled = YES;
//        [tapEditButtonView addGestureRecognizer:singleTap];
//        [actView addSubview:tapEditButtonView];
    }
    else if (self.reuseIdentifier == @"BlueCell"){
        bluePanel = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
        UIImage *bluePanelImage = [UIImage imageNamed:@"bluePanel.png"];
        bluePanel.image = bluePanelImage;
        [actView addSubview:bluePanel];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        
        actNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 260, 30)];
        actNameLabel.text = @"西塘乌镇一日";
        actNameLabel.textAlignment = UITextAlignmentLeft;
        actNameLabel.textColor = [UIColor whiteColor];
        actNameLabel.backgroundColor = [UIColor clearColor];
        actNameLabel.font = [UIFont fontWithName:@"Arial" size:20];
        [bluePanel addSubview:actNameLabel];
        
        wanchengLabel = [[UILabel alloc] initWithFrame:CGRectMake(250, 10, 50, 15)];
        wanchengLabel.text = @"［完成］";
        wanchengLabel.textAlignment = UITextAlignmentLeft;
        wanchengLabel.textColor = [UIColor getColor:@"D0D0D0"];
        wanchengLabel.backgroundColor = [UIColor clearColor];
        wanchengLabel.font = [UIFont fontWithName:@"Arial" size:12];
        [bluePanel addSubview:wanchengLabel];
        
        locationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 55, 11, 16)];
        locationImage = [UIImage imageNamed:@"地点图标"];
        locationImageView.image = locationImage;
        [bluePanel addSubview:locationImageView];
        
        
        locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(32, 55, 100, 16)];
        locationLabel.text = @"杭州市 滨江区";
        locationLabel.textAlignment = UITextAlignmentLeft;
        locationLabel.textColor = [UIColor getColor:@"D0D0D0"];
        locationLabel.backgroundColor = [UIColor clearColor];
        locationLabel.font = [UIFont fontWithName:@"Arial" size:15];
        [bluePanel addSubview:locationLabel];
        
        seperateLineView = [[UIImageView alloc] initWithFrame:CGRectMake(150, 38, 1, 52)];
        seperateLine = [UIImage imageNamed:@"竖分割线"];
        seperateLineView.image = seperateLine;
        [bluePanel addSubview:seperateLineView];
        
        distanceImageView = [[UIImageView alloc] initWithFrame:CGRectMake(175, 55, 15, 15)];
        distanceImage = [UIImage imageNamed:@"距离图标2"];
        distanceImageView.image = distanceImage;
        [bluePanel addSubview:distanceImageView];
        
        distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 53, 100, 19)];
        distanceLabel.text = @"239.7KM";
        distanceLabel.textAlignment = UITextAlignmentLeft;
        distanceLabel.textColor = [UIColor getColor:@"5CC1DE"];
        distanceLabel.backgroundColor = [UIColor clearColor];
        distanceLabel.font = [UIFont fontWithName:@"Arial" size:20];
        [bluePanel addSubview:distanceLabel];
    }
    
    return self;
}


- (void)editButtonTap:(UIGestureRecognizer *)gestureRecognizer
{
    if (isAnimationing)
        return;
    
    if (editButton.image == self.editImage1) {
        [self expandEditPanel];
    }
    else {
        [self collapsEditPanel];
    }
}

-(void) expandEditPanel{
    isAnimationing = YES;
    editButton.image = self.editImage2;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.4f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(myAnimationDidStop:finished:context:)];
    [panel3 setFrame:CGRectMake(0, 30, 300, 70)];
    [UIView commitAnimations];
}

-(void) collapsEditPanel {
    isAnimationing = YES;
    editButton.image = self.editImage1;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.4f];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(myAnimationDidStop:finished:context:)];
    [panel3 setFrame:CGRectMake(0, -40, 300, 70)];
    [UIView commitAnimations];
}
-(void) myAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
    isAnimationing = FALSE;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



@end
